import java.util.HashMap;
import java.util.Map;

public class Solution205 {
    public boolean isIsomorphic(String s, String t) {
        Map<Character,Character> m1=new HashMap<>();
        Map<Character,Character> m2=new HashMap<>();
        for (int i=0;i<s.length();i++){
            if (m1.containsKey(s.charAt(i))||m2.containsKey(t.charAt(i))){
                if (m1.getOrDefault(s.charAt(i),(char)0)!=t.charAt(i) ||m2.getOrDefault(t.charAt(i),(char)0)!=s.charAt(i)){
                    return false;
                }
            }else{
                m1.put(s.charAt(i),t.charAt(i));
                m2.put(t.charAt(i),s.charAt(i));
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new Solution205().isIsomorphic("egg","add"));
    }
}
